package com.ly.honor.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.ly.honor.entity.Country;
import com.ly.honor.entity.Education;
import com.ly.honor.service.EducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author 李某人
 * @Date 2023/3/19 17:29
 * @Version 1.0
 */
@Component
public class EducationConverter implements Converter<Integer> {


    private static EducationService educationService;

    public EducationConverter() {
    }

    @Autowired
    public EducationConverter(EducationService educationService) {
        EducationConverter.educationService = educationService;
    }

    @Override
    public Class<?> supportJavaTypeKey() {
        return Converter.super.supportJavaTypeKey();
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return Converter.super.supportExcelTypeKey();
    }

    @Override
    public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        Education education = educationService.getById(value);
        return new WriteCellData<String>(education.getName());
    }
}
